package com.yc.txx.servlet;

import com.google.gson.Gson;
import com.yc.txx.biz.BizExcpetion;
import com.yc.txx.biz.UserBiz;
import com.yc.txx.entity.Lease;
import com.yc.txx.entity.User;
import com.yc.txx.mapper.LeaseMapper;
import com.yc.txx.util.MyBatisHelper;
import com.yc.txx.vo.Result;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/MyLeasesServlet.s")
public class MyLeasesServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try(SqlSession session = MyBatisHelper.getSession()) {
            LeaseMapper mapper = session.getMapper(LeaseMapper.class);
            User myinfo = (User) request.getSession().getAttribute("myinfo");
            List<Lease> leases = mapper.selectByUid(myinfo.getId());
            String json = new Gson().toJson(leases);
            response.getWriter().append(json);
        }
    }
}